# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=fftw
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=3.3.9
pkgver=${_pkgver//-/.}
pkgrel=2
pkgdesc="A library for computing the discrete Fourier transform (DFT) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.fftw.org"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${url}/${_realname}-${_pkgver}.tar.gz")
sha256sums=('bf2c7ce40b04ae811af714deb512510cc2c17b9ab9d6ddcf49fe4487eea7af3d')

precision="double float long_double \
           $( [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "quad" )"

build() {
  cd "${srcdir}/${_realname}-${_pkgver}"
  for cur in ${precision}; do
    local _config="--enable-sse2 --enable-avx"
    if [ "${cur}" = "float" ]; then
      _config="${_config} --enable-float"
    elif [ "${cur}" = "long_double" ]; then
      _config="--enable-long-double"
    elif [ "${cur}" = "quad" ]; then
      _config="--enable-quad-precision"
    fi
    [[ -d ${MINGW_CHOST}-${cur} ]] && rm -rf ${MINGW_CHOST}-${cur}
    mkdir -p ${MINGW_CHOST}-${cur}
    pushd ${MINGW_CHOST}-${cur} > /dev/null
    msg "Building ${_realname} with ${cur} ..."

    ../configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      ${_config} \
      --enable-static \
      --enable-shared \
      --enable-threads \
      --with-combined-threads \
      --with-our-malloc \
      --with-g77-wrappers \
      --with-windows-f77-mangling
    make

    popd > /dev/null

  done
}

package() {
  cd "${srcdir}/${_realname}-${_pkgver}"
  for cur in ${precision}; do
    pushd ${MINGW_CHOST}-${cur} > /dev/null
    msg "Instaling ${_realname} with ${cur} ..."
    make DESTDIR="${pkgdir}" install
    popd > /dev/null
  done
}
